﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

using Northwind.NET.FE.Forms;
using Northwind.NET.FE.Reports;
using Northwind.NET.Utilities;
using Northwind.NET.FE.zzzSamples;

namespace Northwind.NET.FE
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

                SimpleLogWriter.ResetLog();

                if (!Northwind.NET.FE.Properties.Settings.Default.HideStartUpForm)
                {
                    StartUpForm startUpForm = new StartUpForm();
                    startUpForm.ShowDialog();
                }
                ///////////////////////////////////////////
                // While designing/testing your form or report
                // comment the following line and uncomment
                // the one after the following one and type
                // your form name instead of {{FormName}}
                // placeholders. For the case of reports this
                // will be the name of the form keeping MS Reporviewer
                // control to preview report.
                // Don't forget to comment/uncomment back on
                // committing your current version of code.
                
                Application.Run(new MainSwitchboardForm());
                
                //Application.Run(new QuaterlyOrderForm());
                                
                //Application.Run(new Form1());
                //Application.Run(new CustomerOrdersForm());
                //Application.Run(new {{FormName}}());
                //
                // example:
                //
                //Application.Run(new SuppliersForm()); ;
                ///////////////////////////////////////////
            }
            catch (Exception ex)
            {
                string caption = "Starting " + Northwind.NET.FE.Globals.APPLICATION_TITLE + "...";
                MessageBox.Show(ex.Message + System.Environment.NewLine + System.Environment.NewLine +
                                ex.StackTrace, caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                SimpleLogWriter.WriteLogLine("*** RuntimeError ***");
                SimpleLogWriter.WriteLogLine(ex.StackTrace);
            }
        }

        /// <summary>
        /// Glopbal (catch-all) error handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Exception ex = e.Exception;
            string caption = Northwind.NET.FE.Globals.APPLICATION_TITLE;
            MessageBox.Show(ex.Message + System.Environment.NewLine +  System.Environment.NewLine +
                            ex.StackTrace, caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);

            SimpleLogWriter.WriteLogLine("*** RuntimeError ***");
            SimpleLogWriter.WriteLogLine(ex.StackTrace);   
        }
    }
}